package smedi.ismedi.mobile.bff.controller.configuration;

import com.smedi.ismedi.cache.starter.util.RedisUtil;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import smedi.ismedi.mobile.bff.controller.BaseController;


/**
 * 提供前端所需的配置
 *
 * @author YangJin
 */
@Slf4j
@RestController
@Api(tags = {"配置接口"})
@RequestMapping("/mobilebff/v1/configuration")
@RequiredArgsConstructor
public class ConfigurationController extends BaseController {

    private final RedisUtil redisUtil;

    /**
     * 获取版本号
     *
     * @return 前端配置
     */
    @ApiOperation(httpMethod = "GET", value = "获取配置")
    @GetMapping(value = "/frontendConfiguration")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "configKey", value = "配置Key", dataType = "String"),
    })
    public ResponseData<String> getFrontendConfiguration(String configKey) {
        return new ResponseData<Boolean>().success(String.valueOf(redisUtil.get(configKey)));
    }

    /**
     * 获取版本号
     *
     * @return 修改配置
     */
    @ApiOperation(httpMethod = "GET", value = "修改配置")
    @GetMapping(value = "/setFrontendConfiguration")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "key", value = "key", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "value", value = "value", dataType = "String")
    })
    public ResponseData<Boolean> setFrontendConfiguration(String key, String value) {
        redisUtil.set(key, value);
        return new ResponseData<Boolean>().success(true);
    }
}
